package com.ssyt.blog.core.sys.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ssyt.blog.core.common.PageModel;
import com.ssyt.blog.core.sys.service.ArticleService;
import com.ssyt.blog.core.sys.service.BlogService;
import com.ssyt.blog.core.sys.service.CategoryService;
import com.ssyt.blog.core.sys.service.DiscussService;

@Controller
@RequestMapping("/blog")
public class BlogController {
	@Autowired
	private BlogService blogService;
	@Autowired
	private CategoryService categoryService;
	@Autowired
	private ArticleService articleService;
	@Autowired
	private DiscussService discussService;

	@ResponseBody
	@RequestMapping("/blogInfo")
	public Object getBlogList(Integer pageNo) throws Exception {
		PageModel<Object[]> blogList = blogService.getBlogList(pageNo);
		List<Object> list = new ArrayList<>();
		String[] title = { "博客管理", "编号", "昵称", "个性签名", "注册时间", "所属用户", "操作" };
		list.add(title);
		list.add(blogList);
		return list;
	}

	@ResponseBody
	@RequestMapping(value = { "/blogInfoDelete", "/allBlogInfoDelete" })
	public void blogInfoDelete(Integer id) throws Exception {
		blogService.blogInfoDelete(id);
	}

	@ResponseBody
	@RequestMapping("/categoryInfo")
	public Object getCategoryList(Integer userId, Integer pageNo)
			throws Exception {
		PageModel<Object[]> categoryList = blogService.getCategoryList(userId,
				pageNo);
		List<Object> list = new ArrayList<>();
		String[] title = { "分类管理", "编号", "名称", "所属用户", "操作" };
		list.add(title);
		list.add(categoryList);
		return list;
	}

	@ResponseBody
	@RequestMapping("/allCategoryInfo")
	public Object getCategoryList(Integer pageNo) throws Exception {
		PageModel<Object[]> categoryList = blogService.getCategoryList(null,
				pageNo);
		List<Object> list = new ArrayList<>();
		String[] title = { "分类管理", "编号", "名称", "所属用户", "操作" };
		list.add(title);
		list.add(categoryList);
		return list;
	}

	@ResponseBody
	@RequestMapping(value = { "/categoryInfoDelete", "/allCategoryInfoDelete" })
	public void categoryInfoDelete(Integer id) throws Exception {
		categoryService.categoryInfoDelete(id);
	}

	@ResponseBody
	@RequestMapping("/articleInfo")
	public Object getArticleList(Integer userId, Integer pageNo)
			throws Exception {
		PageModel<Object[]> articleList = blogService.getArticleList(userId,
				pageNo);
		List<Object> list = new ArrayList<>();
		String[] title = { "文章管理", "编号", "标题", "内容", "发表时间", "点击量", "类别",
				"所属用户", "操作" };
		list.add(title);
		list.add(articleList);
		return list;
	}

	@ResponseBody
	@RequestMapping("/allArticleInfo")
	public Object getArticleList(Integer pageNo) throws Exception {
		PageModel<Object[]> articleList = blogService.getArticleList(null,
				pageNo);
		List<Object> list = new ArrayList<>();
		String[] title = { "文章管理", "编号", "标题", "内容", "发表时间", "点击量", "类别",
				"所属用户", "操作" };
		list.add(title);
		list.add(articleList);
		return list;
	}

	@ResponseBody
	@RequestMapping(value = { "/articleInfoDelete", "/allArticleInfoDelete" })
	public void articleInfoDelete(Integer id) throws Exception {
		articleService.articleInfoDelete(id);
	}

	@ResponseBody
	@RequestMapping("/discussInfo")
	public Object getDiscussList(Integer userId, Integer pageNo)
			throws Exception {
		PageModel<Object[]> discussList = blogService.getDiscussList(userId,
				pageNo);
		List<Object> list = new ArrayList<>();
		String[] title = { "回复管理", "编号", "内容", "回复时间", "回复文章", "回复用户", "操作" };
		list.add(title);
		list.add(discussList);
		return list;
	}

	@ResponseBody
	@RequestMapping("/allDiscussInfo")
	public Object getDiscussList(Integer pageNo) throws Exception {
		PageModel<Object[]> discussList = blogService.getDiscussList(null,
				pageNo);
		List<Object> list = new ArrayList<>();
		String[] title = { "回复管理", "编号", "内容", "回复时间", "回复文章", "回复用户", "操作" };
		list.add(title);
		list.add(discussList);
		return list;
	}

	@ResponseBody
	@RequestMapping(value = { "/discussInfoDelete", "/allDiscussInfoDelete" })
	public void discussInfoDelete(Integer id) throws Exception {
		discussService.discussInfoDelete(id);
	}
}
